//重置样式
require('../../assets/css/index.less')

//引入swiper
require('../../assets/lib/swiper/swiper.css')
let Swiper = require('../../assets/lib/swiper/swiper.js')

//引入weui库
require('../../assets/lib/weui/weui.css')
let weui = require('../../assets/lib/weui/weui.js')
console.log(weui);

//当前页面样式
require('./my.less')

//引入字体库
require('../../assets/fonts/iconfont.css')
//引入dom
const dom = require('../../utils/dom.js')
//引入https
const https = require('../../utils/https.js')
//引入local
const local = require('../../utils/local.js')


dom.reday(function () {

    dom.footerH('my')

    //轮播图
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

    })

    //点击跳转
    dom.getEvent('#goPage',function(){
        location.href='personal.html'
    })

    //跳转动态
    dom.getEvent('#goDynamic',function(){
        location.href='circle.html'
    })

    //点击跳转运动数据
    dom.getEvent('#goSports',function(){
        location.href='sportsdata.html'
    })

    //点击跳转徽章
    dom.getEvent('#goBadge',function(){
        location.href='badge.html'
    })

    //获取个人星系
    function getData() {
        https.get('/api/user/info', function (res) {
            console.log(res);
            let { errno, data } = res
            if (errno == 0) {
                dom.getEle('#headUser').src=https.BASE_URL+ data.imgUrl
                dom.getEle('#userId').textContent=data.nickName
                dom.getEle('#sign').textContent='个性签名：'+data.sign
                //数据保存到本地
                local.set('userPro',data)
            }
        })
    }
    getData()
    
        //获取打卡信息
        function getClock() {
            https.get('/api/user/clockInInfo', function (res) {
                let { errno, data } = res
                if (errno == 0) {
                    clockDay.textContent = data.clockCount
                    todayClock.textContent = data.isClockIn ? '已打卡' : '今日打卡'
                }
    
            })
        }
        getClock()
    
        // //打卡
        function setClock() {
    
            dom.getEvent('#todayClock', function () {
                console.log(111);
                https.post('/api/user/clockIn', {}, function (res) {
                    console.log(res);
                    let { errno, message } = res
                    if (errno == -1) {
                        weui.topTips(message)
                    }else{
                        weui.toast('打卡成功')
                        getClock()
                    }
                })
            })
    
    
        }
        setClock()


        //运动数据渲染
        function spoData(){
            https.get('/api/exercise',function(res){
                console.log(res);
                let {errno,data}=res
                if(errno==0){
                   dom.getEle('#sporTime').textContent=data.sum7Duration
                   dom.getEle('#sporCalorie').textContent=data.sum7Calorie
                }
            })
        }

        spoData()





})